package com.zlzxm.shoesmarket.view.adapter;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.view.adapter.entity.SectionNote;

import org.jetbrains.annotations.NotNull;

/**
 * CREATE BY zlzxm ON 4/21/21
 */
public class ADNote extends BaseSectionQuickAdapter<SectionNote, BaseViewHolder> {


    ForegroundColorSpan addColorSpan;
    ForegroundColorSpan subColorSpan;

    public ADNote() {
        super(R.layout.section_note, R.layout.item_note,null);
        addColorSpan = new ForegroundColorSpan(Color.parseColor("#EF7020"));
        subColorSpan = new ForegroundColorSpan(Color.parseColor("#0C0C0C"));
    }

    @Override
    protected void convertHeader(@NotNull BaseViewHolder holder, @NotNull SectionNote section) {

        holder.setText(R.id.tvTime,section.getHead());
        holder.setText(R.id.tvDesc,section.getDesc());


    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, SectionNote section) {

        holder.setText(R.id.tvKey,section.getEntityNote().getTitle());

        String desc  = section.getEntityNote().getDesc();

        if(section.getEntityNote()!=null) {

            if (desc.startsWith("+")) {

                SpannableString spannableString = new SpannableString(desc);

                spannableString.setSpan(addColorSpan,0,desc.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);

                holder.setText(R.id.tvDesc, spannableString);

            } else if (desc.startsWith("-")) {

                SpannableString spannableString = new SpannableString(desc);

                spannableString.setSpan(subColorSpan,0,desc.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);

                holder.setText(R.id.tvDesc, spannableString);

            } else {

                holder.setText(R.id.tvDesc, section.getEntityNote().getDesc());

            }
        }
    }
}
